﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Topro.Admin.Controllers
{
    using Topro.Application.Interface;

    using Topro.Entity;
    using Topro.Entity.Enum;
    using Topro.Entity.Query;
    using Topro.Entity.Request.IQS;
    using Topro.Entity.Response.IQS;
    using Topro.Util;

    /// <summary>
    /// 默认控制器
    /// </summary>
    public class DefaultController : Controller
    {
        #region 注入
        /// <summary>
        /// 
        /// </summary>
        private readonly IWebHostEnvironment _hostEnvironment;

        /// <summary>
        /// IQS接口
        /// </summary>
        private readonly IQSService _iqsService;

        /// <summary>
        /// 字典接口
        /// </summary>
        private readonly DictionaryService _dictionaryService;

        /// <summary>
        /// 设备数据接口
        /// </summary>
        private readonly DeviceDataService _deviceDataService;

        /// <summary>
        /// 设置接口
        /// </summary>
        private readonly ConfigService _configService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="hostEnvironment">IQS接口</param>
        /// <param name="authService">IQS接口</param>
        /// <param name="dictionaryService">字典接口</param>
        /// <param name="deviceDataService">设备数据接口</param>
        /// <param name="settingService">设置接口</param>
        public DefaultController(IWebHostEnvironment hostEnvironment,IQSService iqsService, DictionaryService dictionaryService, DeviceDataService deviceDataService, ConfigService configService)
        {
            _hostEnvironment = hostEnvironment;
            _iqsService = iqsService;
            _dictionaryService = dictionaryService;
            _deviceDataService = deviceDataService;
            _configService = configService;
        }
        #endregion

        #region 首页
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Index()
        {
            var response = new UIIQSResponse();
            //获取所有字典
            var list = _dictionaryService.GetByList();
            //验证是否为空
            if(list!=null && list.Any())
            {
                //var partNumModel = list.FirstOrDefault(c => c.Type == (int)DictionaryFiled.厂号);
                //if (partNumModel != null)
                //{
                //    response.PartNum = partNumModel.Name;
                //}
                //班次
                //var shiftNumList = list.Where(c => c.Type == (int)DictionaryFiled.班次).OrderBy(c=>c.DisplayOrder);
                //if (shiftNumList != null && shiftNumList.Any())
                //{
                //    var dic = new Dictionary<string, string>(); 

                //    foreach (var item in shiftNumList)
                //    {
                //        dic.Add(item.Name, item.Value);
                //    }

                //    response.ShiftNum = dic;
                //}
                //设备编码
                //var equipmentCodeModel = list.FirstOrDefault(c => c.Type == (int)DictionaryFiled.设备编码);
                //if (equipmentCodeModel != null)
                //{
                //    response.EquipmentCode = equipmentCodeModel.Name;
                //}
                //Postponed Material延期材料1
                //var postponedMaterialList = list.Where(c => c.Type == (int)DictionaryFiled.延期材料1).OrderBy(c => c.DisplayOrder);
                //if (postponedMaterialList != null && postponedMaterialList.Any())
                //{
                //    var dic = new Dictionary<string, string>();

                //    foreach (var item in postponedMaterialList)
                //    {
                //        dic.Add(item.Name, item.Value);
                //    }

                //    response.PostponedMaterial1 = dic;
                //}
            }
            //Postponed Material1零包OR整包
            response.PostponedMaterialType = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PostponedMaterialType));
            //延期材料
            response.PostponedMaterial = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PostponedMaterialType));
            //Stopper Quality 防滑质量
            response.StopperQuality = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(StopperQuality));
            //Perpreg Surface Quality 表面质量
            response.PerpregSurfaceQuality = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PerpregSurfaceQuality));
            //14 Pcs Kraft Quality 14张牛皮纸数量
            response.PcsKraftQuality = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(PcsKraftQuality));
            //Inner Core Quality 内层芯板质量
            response.InnerCoreQuality = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(InnerCoreQuality));
            //Copper Foil Quality 铜箔质量
            response.CopperFoilQuality = (Dictionary<int, string>)EnumUtil.ToDictionary(typeof(CopperFoilQuality));

            return View(response);
        }
        #endregion

        #region 选择
        /// <summary>
        /// 选择
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Select(int type)
        {
            ViewBag.Type = type;
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>PagedList<PermissionResponse></returns>
        [HttpGet]
        public IActionResult SelectQuery(DictionaryQuery query)
        {
            var list = _dictionaryService.GetSelectTypePager(query);

            return PartialView("_Query", list);
        }
        #endregion

        #region 条码验证

        #region Lot 批号(上条码)
        /// <summary>
        /// Lot 批号(上条码)
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult LotBatch(string content)
        {
            var response = new JResult<LotBatchResponse>()
            {
                Success = false
            };

            try
            {
                var data = new LotBatchResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Lot 批号(上条码)不能为空.");
                }

                var arr = content.Split("|");

                if (arr.Length != 3)
                {
                    throw new Exception("Lot 批号(上条码)格式有误.");
                }

                //批号
                data.LotBatch = arr[0];
                //料号
                data.PartNum = arr[1];
                //叠合次数号
                data.HeapNumber = arr[2].Replace("010", "");
                //材料类型
                data.MaterialType = "Cu_pp";
                //提示
                data.Tips = "";

                #region 操作设定
                var opSetUpList = _configService.GetTypeList((int)SettingType.操作设定);
                if(opSetUpList != null && opSetUpList.Any())
                {
                    //验证LotBatch是否存在.
                    var lotBatchExist = opSetUpList.Any(c => c.LotNo == data.LotBatch);
                    if (lotBatchExist)
                    {
                        //NYA1190;NYA1191
                        //料号
                        var partNum = "";
                        //料号长度
                        var partNumLength = data.PartNum.Length;
                        //验证料号长度是否等于5、6、7
                        if (partNumLength == 5 || partNumLength == 6 || partNumLength == 7)
                        {
                            partNum = data.PartNum.Substring(0, partNumLength - 1);
                        }

                        var config = opSetUpList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.Tips = config.Value;
                        }
                    }
                    else
                    {
                        //NYA1190;NYA1191
                        //料号
                        var partNum = "";
                        //料号长度
                        var partNumLength = data.PartNum.Length;
                        //验证料号长度是否等于5、6、7
                        if (partNumLength == 5 || partNumLength == 6 || partNumLength == 7)
                        {
                            partNum = data.PartNum.Substring(0, partNumLength - 1);
                        }

                        var config = opSetUpList.FirstOrDefault(c => c.PartNo.Contains(partNum) && c.LotNo == null && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.Tips = config.Value;
                        }
                    }
                }
                #endregion

                #region 程序设定
                var pressProgramList = _configService.GetTypeList((int)SettingType.程序);
                if (pressProgramList != null && pressProgramList.Any())
                {
                    //验证LotBatch是否存在.
                    var lotBatchExist = pressProgramList.Any(c => c.LotNo == data.LotBatch);
                    if (lotBatchExist)
                    {
                        var config = pressProgramList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.PressProgram = config.Value;
                        }
                    }
                    else
                    {
                        var config = pressProgramList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == null && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.PressProgram = config.Value;
                        }
                    }
                }
                #endregion

                #region Book结构
                var bookSetUpList = _configService.GetTypeList((int)SettingType.Book结构);
                if (bookSetUpList != null && bookSetUpList.Any())
                {
                    //验证LotBatch是否存在.
                    var lotBatchExist = bookSetUpList.Any(c => c.LotNo == data.LotBatch);
                    if (lotBatchExist)
                    {
                        var config = bookSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.BookBuildupStructure = config.Value;
                        }
                    }
                    else
                    {
                        var config = bookSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == null && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.BookBuildupStructure = config.Value;
                        }
                    }
                }
                #endregion

                #region 叠板片数设定
                var heapSetUpList = _configService.GetTypeList((int)SettingType.叠板片数设定);
                if (heapSetUpList != null && heapSetUpList.Any())
                {
                    //验证LotBatch是否存在.
                    var lotBatchExist = heapSetUpList.Any(c => c.LotNo == data.LotBatch);
                    if (lotBatchExist)
                    {
                        var config = heapSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == data.LotBatch && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.SecionQuan = config.Value;
                        }
                    }
                    else
                    {
                        var config = heapSetUpList.FirstOrDefault(c => c.PartNo == data.PartNum && c.LotNo == null && c.Cycle == data.HeapNumber);
                        if (config != null)
                        {
                            data.SecionQuan = config.Value;
                        }
                    }
                }
                #endregion

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region programbarCode 物料/程式信息(下条码)
        /// <summary>
        /// 物料/程式信息(下条码)
        /// </summary>
        [HttpPost]
        public IActionResult ProgrambarCode(string content)
        {
            var response = new JResult<ProgrambarCodeResponse>()
            {
                Success = false
            };

            try
            {
                var data = new ProgrambarCodeResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("扫码内容不能为空.");
                }

                var arr = content.Split("|");

                if (arr.Length != 6)
                {
                    throw new Exception("扫码内容格式有误.");
                }

                data.CuFoilNum = arr[0];
                data.PPRCFPartNum1 = arr[1];
                data.PPRCFPartNum2 = arr[2];
                data.PressProgram = arr[3];
                data.BookBuildupStructure = arr[4];
                //获取压合程式所有数据
                var dictionaryList = _dictionaryService.GetByType((int)DictionaryFiled.压合程式);
                if(dictionaryList!=null && dictionaryList.Any())
                {
                    var dictionary = dictionaryList.FirstOrDefault(c => c.Value.Replace(" ", "").Contains(arr[3]));
                    if (dictionary != null)
                    {
                        data.PressProgram = dictionary.Name;
                    }
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Cu Foil Num 铜箔编号
        /// <summary>
        /// Cu Foil Num 铜箔编号
        /// </summary>
        [HttpPost]
        public IActionResult CuFoilNum(string cuFoilNum, string content)
        {
            var response = new JResult<CuFoilNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new CuFoilNumResponse();

                if (string.IsNullOrEmpty(cuFoilNum))
                {
                    throw new Exception("铜箔编号不能为空.");
                }

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("扫码内容不能为空.");
                }

                var arr = content.Split("*");

                if (arr.Length < 2)
                {
                    throw new Exception("扫码内容格式有误.");
                }

                //铜箔编号
                data.CuFoilNum = arr[0];
                //铜箔批号
                var cufoilBatch = arr[1];

                if(arr.Length >= 3)
                {
                    cufoilBatch += $"*{arr[1]}";
                }

                data.CuFoilBatch = cufoilBatch;

                if (data.CuFoilNum != cuFoilNum)
                {
                    throw new Exception("与物料/程式信息铜箔编号不复.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Cu Foil Expire 铜箔有效期
        /// <summary>
        /// Cu Foil Expire 铜箔有效期
        /// </summary>
        [HttpPost]
        public IActionResult CuFoilExpire(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 必须大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Cu Foil Expire 铜箔有效期不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"Cu Foil Expire 铜箔有效期[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception(@$"Cu Foil Expire 铜箔有效期[{content}]必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号1_1
        /// <summary>
        /// Package Num包号1
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum1_1(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号1_1不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if(arr.Length == 2)
                {
                    data.PackageNum = arr[0];
                }
                else if (arr.Length == 3)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                }
                else
                {
                    throw new Exception("Package Num包号1_1格式有误.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号1_1
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public JsonResult PpPcfPartNum1_1(string LOTPPRCFPartNum1, string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(LOTPPRCFPartNum1))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号1内容不能为空.");
                }

                var status = content.Contains(";");

                if(status)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length == 4)
                    {
                        data.PPPcfPartNum1 = arr[0];
                        data.PPPcfBatchNum1 = arr[1];
                    }
                    else
                    {
                        throw new Exception("料号1内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414910|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    if (arr.Length != 11)
                    {
                        var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                        if (partNum != null)
                        {
                            data.PPPcfPartNum1 = partNum.Replace("0241","");
                        }

                        var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                        if (batchNum != null)
                        {
                            data.PPPcfBatchNum1 = batchNum.Replace("0010","");
                        }
                    }
                    else
                    {
                        throw new Exception("料号1内容格式有误.");
                    }
                }

                //var data = new List<string>();


                //if (data[0] != LOTPPRCFPartNum1)
                //{
                //    throw new Exception(@$"与物料/程式信息(下条码)******|{LOTPPRCFPartNum1}|******|*****|****|******不匹配.");
                //}

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期1_1
        /// <summary>
        /// PP/PCF 有效期1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire1_1(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期1_1不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期1_1[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期1_1必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号1_2
        /// <summary>
        /// Package Num包号1
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum1_2(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号1_2不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length == 2)
                {
                    data.PackageNum = arr[0];
                }
                else if (arr.Length == 3)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                }
                else
                {
                    throw new Exception("Package Num包号1_2格式有误.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号1_2
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public JsonResult PpPcfPartNum1_2(string LOTPPRCFPartNum1, string content)
        {
            var response = new JResult<PpPcfPartNum1_1Response>()
            {
                Success = false
            };

            try
            {
                var data = new PpPcfPartNum1_1Response();

                if (string.IsNullOrEmpty(LOTPPRCFPartNum1))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号1内容不能为空.");
                }

                var status = content.Contains(";");

                if (status)
                {
                    //料号   批号
                    //414910;21A042M01A3;240;
                    var arr = content.Split(";");

                    if (arr.Length == 4)
                    {
                        data.PPPcfPartNum1 = arr[0];
                        data.PPPcfBatchNum1 = arr[1];
                    }
                    else
                    {
                        throw new Exception("料号1内容格式有误.");
                    }
                }
                else
                {
                    //	              0241料号           0010批号
                    //|00404500948712|0241414910|0037240|001021A042M01A3|0036036|0011211004|0412470433|0048|
                    //
                    var arr = content.Split("|");

                    if (arr.Length != 11)
                    {
                        var partNum = arr.FirstOrDefault(c => c.Contains("0241"));
                        if (partNum != null)
                        {
                            data.PPPcfPartNum1 = partNum.Replace("0241", "");
                        }

                        var batchNum = arr.FirstOrDefault(c => c.Contains("0010"));
                        if (batchNum != null)
                        {
                            data.PPPcfBatchNum1 = batchNum.Replace("0010", "");
                        }
                    }
                    else
                    {
                        throw new Exception("料号1内容格式有误.");
                    }
                }

                //var data = new List<string>();


                //if (data[0] != LOTPPRCFPartNum1)
                //{
                //    throw new Exception(@$"与物料/程式信息(下条码)******|{LOTPPRCFPartNum1}|******|*****|****|******不匹配.");
                //}

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期1_2
        /// <summary>
        /// PP/PCF 有效期1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire1_2(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期1_2不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期1_2[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期1_2必须大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号2_1
        /// <summary>
        /// Package Num包号2
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum2_1(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号2_1不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length == 2)
                {
                    data.PackageNum = arr[0];
                }
                else if (arr.Length == 3)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                }
                else
                {
                    throw new Exception("Package Num包号2_1格式有误.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号2_1
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfPartNum2_1(string LOTPPRCFPartNum2, string content)
        {
            var response = new JResult<List<string>>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(LOTPPRCFPartNum2))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号2_1内容不能为空.");
                }

                var arr = content.Split(";");

                if (arr.Length != 4)
                {
                    throw new Exception("料号2_1内容格式有误.");
                }

                var data = new List<string>();
                foreach (var item in arr)
                {
                    data.Add(item);
                }

                if (data[0] != LOTPPRCFPartNum2)
                {
                    throw new Exception(@$"与物料/程式信息(下条码)******|******|{LOTPPRCFPartNum2}|*****|****|******不匹配.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期2_1
        /// <summary>
        /// PP/PCF 有效期2
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire2_1(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期2_1不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期2_1[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date < now)
                {
                    throw new Exception("PP/PCF 有效期2_1必须当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Package Num包号2_2
        /// <summary>
        /// Package Num包号2
        /// </summary>
        [HttpPost]
        public IActionResult PackageNum2_2(string content)
        {
            var response = new JResult<PackageNumResponse>()
            {
                Success = false
            };

            try
            {
                var data = new PackageNumResponse();

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("Package Num包号2_2不能为空.");
                }

                //21-1018-0936222022/01/11;240
                //21-1018-093622;2022/01/11;240
                var arr = content.Split(";");

                if (arr.Length == 2)
                {
                    data.PackageNum = arr[0];
                }
                else if (arr.Length == 3)
                {
                    data.PackageNum = arr[0];
                    data.PackageExpire = arr[1];
                }
                else
                {
                    throw new Exception("Package Num包号2_2格式有误.");
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 料号2_2
        /// <summary>
        /// PP/PCF 料号1
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfPartNum2_2(string LOTPPRCFPartNum2, string content)
        {
            var response = new JResult<List<string>>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(LOTPPRCFPartNum2))
                {
                    throw new Exception("料号不能为空.");
                }

                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("料号2_2内容不能为空.");
                }

                var arr = content.Split(";");

                if (arr.Length != 4)
                {
                    throw new Exception("料号2_2内容格式有误.");
                }

                var data = new List<string>();
                foreach (var item in arr)
                {
                    data.Add(item);
                }

                if (data[0] != LOTPPRCFPartNum2)
                {
                    throw new Exception(@$"与物料/程式信息(下条码)******|******|{LOTPPRCFPartNum2}|*****|****|******不匹配.");
                }

                response.Success = true;
                response.Data = data;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region PP/PCF 有效期2_2
        /// <summary>
        /// PP/PCF 有效期2
        /// </summary>
        [HttpPost]
        public IActionResult PpPcfExpire2_2(string content)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                /**
                 * 不能大于当前时间
                 */
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("PP/PCF 有效期2_2不能为空.");
                }
                //验证是否日期格式
                if (!Topro.Util.DateUtil.IsDateTime(content))
                {
                    throw new Exception(@$"PP/PCF 有效期2_2[{content}]格式有误.");
                }

                //当前时期
                var now = DateTime.Now;
                //输入时期
                var reqeust = Convert.ToDateTime(content);
                //验证
                if (reqeust.Date > now)
                {
                    throw new Exception("PP/PCF 有效期2_2不能大于当前时间.");
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Alpha Board Stay Time棕化停留时间
        /// <summary>
        /// Alpha Board Stay Time棕化停留时间
        /// </summary>
        [HttpPost]
        public IActionResult AlphaBoardStayTime(string content)
        {
            var response = new JResult<string>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("棕化停留时间不能为空.");
                }

                var nameReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!nameReg.IsMatch(content))
                {
                    throw new Exception("棕化停留时间只能输入正整数");
                }

                response.Success = true;
                response.Data = content;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #region Abnormal Steel Plate Quantity异常钢板数量
        /// <summary>
        /// Abnormal Steel Plate Quantity异常钢板数量
        /// </summary>
        [HttpPost]
        public IActionResult AbnormalSteelPlateQuantity(string content)
        {
            var response = new JResult<string>()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("异常钢板数量不能为空.");
                }

                var nameReg = new Regex(@"^[+]{0,1}(\d+)$");
                if (!nameReg.IsMatch(content))
                {
                    throw new Exception("异常钢板数量只能输入正整数");
                }

                response.Success = true;
                response.Data = content;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #endregion

        #region 限制

        #region 员工限制
        /// <summary>
        /// 员工限制
        /// </summary>
        [HttpPost]
        public IActionResult StaffLimit(string staffNum)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                if (string.IsNullOrEmpty(staffNum))
                {
                    throw new Exception("料号不能为空.");
                }


                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return Json(response);
        }
        #endregion

        #endregion

    }
}
